﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Ribbon.Core;
using System.Reflection;
using Ribbon.Core.Menu;

namespace Ribbon.Demo
{
    public partial class Form1 : Form
    {
        private Ribbon.Core.Ribbon ribbon = null;

        private TextBoxDemo tb = null;

        public Form1()
        {
            InitializeComponent();

            SetCss();

            //LoadTextBox();

            LoadRibbon();
        }

        private void SetCss()
        {
            Type dgvType = this.dataGridView1.GetType();//首先定义DataGridView的Type类

            //System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic:表示寻找的范围是示例成员以及非公开成员
            PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

            //通过Type类，反射出DoubleBuffered的属性值。
            pi.SetValue(this.dataGridView1, true, null);//将DoubleBuffered属性值设置为True

            dataGridView1.RowCount = 100;

            this.BackColor = Color.White;

            
        }

        private void LoadTextBox()
        {
            for (int i = 0; i < this.Controls.Count; i++)
            {
                if (this.Controls[i] is Button)
                    continue;

                this.Controls.RemoveAt(i);

                i--;
            }

            TextBox box = new TextBox();

            box.Size = new System.Drawing.Size(200, 30);

            box.Location = new Point(350, 100);

            this.Controls.Add(box);

            TextBoxDemo tb = new TextBoxDemo();

            tb.Font = new System.Drawing.Font("微软雅黑", 28f);

            int height = 30;

            tb.Size = new System.Drawing.Size(200, height);

            tb.Location = new Point(100, 100);

            tb.Radiu = 10;

            this.Controls.Add(tb);

            //System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            //{
            //    int scale = -10;
            //    while (true)
            //    {
            //        System.Threading.Thread.Sleep(500);

            //        if (this.IsHandleCreated)
            //        {
            //            this.BeginInvoke((Action)(() =>
            //            {
            //                tb.Size = new System.Drawing.Size(200, height);

            //                tb.Refresh();

            //                height += scale;

            //                if (height <= 0)
            //                {
            //                    scale = 10;
            //                }
            //                else if (height > 100)
            //                {
            //                    scale = -10;
            //                }
            //            }));
            //        }
            //        else
            //        {
            //            break;
            //        }
            //    }
            //}));

            //thread.Start();

            return;
        }

        private void LoadRibbon()
        {
            System.Diagnostics.Stopwatch sb = new System.Diagnostics.Stopwatch();

            sb.Start();

            this.pictureBox1.Image = new Bitmap(Application.StartupPath + @"\res\32\Menu.png");

            ribbon = new Core.Ribbon();

            ribbon.Initialize();

            RibbonMenu me1 = new RibbonMenu("文件");
            me1.BackColor = Color.FromArgb(222, 222, 222);
            me1.ForeColor = Color.FromArgb(1, 1, 1);
            me1.SelectBackColor = Color.FromArgb(85, 153, 229);
            me1.SelectForeColor = Color.FromArgb(255, 255, 255);
            me1.Radiu = 1f;
            me1.Image = new Bitmap(Application.StartupPath + @"\res\32\menu.png");
            //me1.Image = new Bitmap(Application.StartupPath + @"\res\_66.ico");

            RibbonMenuItem it1 = new RibbonMenuItem("aaaa"); it1.Image = new Bitmap(Application.StartupPath + @"\res\32\Menu.png");
            RibbonMenuItem it2 = new RibbonMenuItem("bbbb"); it2.Image = new Bitmap(Application.StartupPath + @"\res\16\undo.png");
            RibbonMenuItem it3 = new RibbonMenuItem("cccc"); it3.Image = new Bitmap(Application.StartupPath + @"\res\16\undo.png");

            me1.Items.Add(it1);
            me1.Items.Add(it2);
            me1.Items.Add(it3);

            ribbon.Pages.Add(me1);

            RibbonSplitPage sp1 = new RibbonSplitPage();
            sp1.BackColor = Color.FromArgb(209, 209, 209);

            ribbon.Pages.Add(sp1);

            RibbonPageButton bt1 = new RibbonPageButton("11");

            bt1.Image = new Bitmap(Application.StartupPath + @"\res\16\undo.png");
            bt1.BackColor = Color.FromArgb(222, 222, 222);
            bt1.ForeColor = Color.FromArgb(1, 1, 1);
            bt1.SelectBackColor = Color.FromArgb(222, 222, 222);
            bt1.SelectForeColor = Color.FromArgb(255, 255, 255);
            bt1.Radiu = 5f;

            RibbonPageButton bt2 = new RibbonPageButton("22");
            bt2.Image = new Bitmap(Application.StartupPath + @"\res\16\redo.png");
            bt2.BackColor = Color.FromArgb(222, 222, 222);
            bt2.ForeColor = Color.FromArgb(1, 1, 1);
            bt2.SelectBackColor = Color.FromArgb(222, 222, 222);
            bt2.SelectForeColor = Color.FromArgb(255, 255, 255);
            bt2.Radiu = 5f;

            ribbon.Pages.AddRange(bt1, bt2);

            RibbonPage page1 = new RibbonPage("主页");
            page1.BackColor = Color.FromArgb(222, 222, 222);
            page1.ForeColor = Color.FromArgb(1, 1, 1);
            page1.SelectBackColor = Color.FromArgb(85, 153, 229);
            page1.SelectForeColor = Color.FromArgb(255, 255, 255);
            page1.Radiu = 18f;

            RibbonPage page2 = new RibbonPage("给排水");
            page2.BackColor = Color.FromArgb(222, 222, 222);
            page2.ForeColor = Color.FromArgb(1, 1, 1);
            page2.SelectBackColor = Color.FromArgb(83, 173, 83);
            page2.SelectForeColor = Color.FromArgb(255, 255, 255);
            page2.Radiu = 15f;

            RibbonPage page3 = new RibbonPage("通风排烟");
            page3.BackColor = Color.FromArgb(222, 222, 222);
            page3.ForeColor = Color.FromArgb(1, 1, 1);
            page3.SelectBackColor = Color.FromArgb(83, 173, 83);
            page3.SelectForeColor = Color.FromArgb(255, 255, 255);
            page3.Radiu = 23f;

            RibbonPage page4 = new RibbonPage("电气工程");
            page4.BackColor = Color.FromArgb(222, 222, 222);
            page4.ForeColor = Color.FromArgb(1, 1, 1);
            page4.SelectBackColor = Color.FromArgb(83, 173, 83);
            page4.SelectForeColor = Color.FromArgb(255, 255, 255);
            page4.Radiu = 10f;

            RibbonPage page5 = new RibbonPage("弱电智能化");
            page5.BackColor = Color.FromArgb(222, 222, 222);
            page5.ForeColor = Color.FromArgb(1, 1, 1);
            page5.SelectBackColor = Color.FromArgb(83, 173, 83);
            page5.SelectForeColor = Color.FromArgb(255, 255, 255);
            page5.Radiu = 10f;

            ribbon.Pages.AddRange(new RibbonPage[] { 
                page1,page2,page3,page4,page5
            });

            RibbonGroup group1 = new RibbonGroup("组1"); group1.BackColor = Color.Red;
          
            RibbonGroup group2 = new RibbonGroup("组2"); group2.BackColor = Color.Black;
            RibbonGroup group3 = new RibbonGroup("组3"); group3.BackColor = Color.Yellow;

            RibbonGroup group4 = new RibbonGroup("组4"); group4.BackColor = Color.BlanchedAlmond;
            RibbonGroup group5 = new RibbonGroup("组5"); group5.BackColor = Color.Turquoise;
            RibbonGroup group6 = new RibbonGroup("组6"); group6.BackColor = Color.PaleGreen;

            page1.Groups.AddRange(group1, group2, group3);

            page2.Groups.AddRange(group4, group5, group6);

            RibbonItem item1 = new RibbonItem("打开文件"); item1.Location = new PointF(5f, 5f); item1.Image = new Bitmap(Application.StartupPath + @"\res\16\redo.png");
            RibbonItem item2 = new RibbonItem("关闭文件"); item2.Location = new PointF(85f, 5f); item2.Image = new Bitmap(Application.StartupPath + @"\res\16\undo.png");
            RibbonItem item3 = new RibbonItem("历史记录"); item3.Location = new PointF(5f, 30f);
            RibbonItem item4 = new RibbonItem("刷新"); item4.Location = new PointF(65f, 30f);

            RibbonItem item5 = new RibbonItem("功能1"); item5.Location = new PointF(5f, 5f);
            RibbonItem item6 = new RibbonItem("功能2"); item6.Location = new PointF(48f, 5f);
            RibbonItem item7 = new RibbonItem("功能3"); item7.Location = new PointF(92f, 5f);
            RibbonItem item8 = new RibbonItem("功能4"); item8.Location = new PointF(5f, 30f);
            RibbonItem item9 = new RibbonItem("功能5"); item9.Location = new PointF(48f, 30f);
            RibbonItem item10 = new RibbonItem("功能6"); item10.Location = new PointF(92f, 30f);

            RibbonItem item11 = new RibbonItem("item11"); item11.Location = new PointF(5f, 5f);
            RibbonItem item12 = new RibbonItem("item12"); item12.Location = new PointF(5f, 5f);
            RibbonItem item13 = new RibbonItem("item13"); item13.Location = new PointF(5f, 5f);
            RibbonItem item14 = new RibbonItem("item14"); item14.Location = new PointF(5f, 5f);
            RibbonItem item15 = new RibbonItem("item15"); item15.Location = new PointF(5f, 5f);
            RibbonItem item16 = new RibbonItem("item16"); item16.Location = new PointF(5f, 5f);

            RibbonCheckBoxItem item17 = new RibbonCheckBoxItem("功能item17"); item17.Location = new PointF(5f, 5f);

            RibbonFillColorItem item18 = new RibbonFillColorItem("功能item18");
            item18.Location = new PointF(120f, 5f);
            item18.Size = new SizeF(32, 20);
            item18.ContentImage = new Bitmap(Application.StartupPath + @"\res\fill.png");
            item18.DropImage = new Bitmap(Application.StartupPath + @"\res\dropdown.png");

            RibbonTextColorItem item19 = new RibbonTextColorItem("功能item19");
            item19.Location = new PointF(160f, 5f);
            item19.Size = new SizeF(32, 20);
            item19.ContentImage = new Bitmap(Application.StartupPath + @"\res\a.png");
            item19.DropImage = new Bitmap(Application.StartupPath + @"\res\dropdown.png"); 

            group1.Items.Add(item1);
            group1.Items.Add(item2);
            group1.Items.Add(item3);
            group1.Items.Add(item4);

            group2.Items.Add(item5);
            group2.Items.Add(item6);
            group2.Items.Add(item7);
            group2.Items.Add(item8);
            group2.Items.Add(item9);
            group2.Items.Add(item10);

            group3.Items.Add(item17);
            group3.Items.Add(item18);
            group3.Items.Add(item19);

            group4.Items.AddRange(item11
           , item12
           , item13
           , item14
           , item15
           , item16);

            this.Controls.Add(ribbon);

            ribbon.EndInitialize();

            sb.Stop();

            Console.WriteLine(sb.ElapsedMilliseconds);
        }
    }
}
